<template>
  <div>
    <el-menu
      class="el-menu-vertical-demo"
      :default-active="activeMenu"
      background-color="#fff"
      :collapse="false"
      :unique-opened="true"
      :active-text-color="variables.menuColorActive"
      :collapse-transition="false"
      mode="vertical"
      @select="menuSelect"
    >
      <sidebar-item
        v-for="(route, index) in sidebarRouters"
        :key="route.path + index"
        :item="route"
        :base-path="route.path"
      />
    </el-menu>
  </div>
</template>

<script>
import SidebarItem from './SidebarItem.vue'
import variables from '@/assets/styles/common.scss'
export default {
  name: 'AppSidebar',
  components: { SidebarItem },
  props: {
    sidebarRouters: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      variables,
    }
  },
  computed: {
    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    },
  },
  methods: {
    menuSelect(index, indexPath) {
      this.$emit('menuSelect', indexPath)
    },
  },
}
</script>

<style lang="scss" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 220px;
  height: 100vh;
}
</style>
